home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / AMesaRTL.lha / Mesa-2.6 / amiga / lib / MesaAuto.c < prev    next >
C/C++ Source or Header  |  1998-09-19  |  3KB  |  129 lines

  1.  
  2. /*
  3.  * AmigaMesaRTL graphics library
  4.  * Version:  2.0
  5.  * Copyright (C) 1998  Jarno van der Linden
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Library General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Library General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Library General Public
  18.  * License along with this library; if not, write to the Free
  19.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  */
  21.  
  22.  
  23. /*
  24.  * mesaauto.c
  25.  *
  26.  * Version 1.0  27 Jun 1998
  27.  * by Jarno van der Linden
  28.  * jarno@kcbbs.gen.nz
  29.  *
  30.  * Version 1.1  02 Aug 1998
  31.  * by Jarno van der Linden
  32.  * jarno@kcbbs.gen.nz
  33.  *
  34.  * - Added __stack to set enough stack
  35.  *
  36.  * Version 2.0  06 Sep 1998
  37.  * by Jarno van der Linden
  38.  * jarno@kcbbs.gen.nz
  39.  *
  40.  * - Opens v2.0 libraries
  41.  * - Driver got through mesaGetAttr()
  42.  *
  43.  */
  44.  
  45.  
  46. #include <exec/types.h>
  47. #include <constructor.h>
  48.  
  49. #include <proto/dos.h>
  50. #include <proto/exec.h>
  51. #include <string.h>
  52.  
  53. #include "gl/mesamain.h"
  54. #include "gl/mesadriver.h"
  55.  
  56. extern struct WBStartup *_WBenchMsg;
  57. extern char __stdiowin[];
  58.  
  59. struct Library *mesamainBase;
  60. struct Library *mesadriverBase;
  61. static void *mainlibbase;
  62.  
  63. long __stack = 65536;
  64.  
  65. void mesaautoopenfail(char *lib, int ver)
  66. {
  67.    struct DOSBase *DOSBase;
  68.    long fh;
  69.    char buf[50];
  70.  
  71.    DOSBase = (struct DOSBase *)OpenLibrary("dos.library",0);
  72.    if (_WBenchMsg == NULL)
  73.       fh = Output();
  74.    else
  75.       fh = Open(__stdiowin, MODE_NEWFILE);
  76.  
  77.    if (fh)
  78.    {
  79.        RawDoFmt("Can't open version %ld of ",
  80.                 &ver, (void (*))"\x16\xC0\x4E\x75", buf);
  81.  
  82.        Write(fh, buf, strlen(buf));
  83.        Write(fh, lib, strlen(lib));
  84.        Write(fh, "\n", 1);
  85.  
  86.        if (_WBenchMsg)
  87.        {
  88.            Delay(200);
  89.            Close(fh);
  90.        }
  91.    }
  92.  
  93.  
  94.    CloseLibrary((struct Library *)DOSBase);
  95.    ((struct Process *)FindTask(NULL))->pr_Result2 =
  96.                       ERROR_INVALID_RESIDENT_LIBRARY;
  97.  
  98. }
  99.  
  100. CBMLIB_CONSTRUCTOR(openmesa)
  101. {
  102.    mesamainBase = mainlibbase =
  103.        (void *)OpenLibrary("mesamain.library", 2);
  104.    if (mesamainBase == NULL)
  105.    {
  106.      mesaautoopenfail("mesamain.library", 2);
  107.      return 1;
  108.    }
  109.  
  110.    mesaGetAttr(MESA_DriverBase,&mesadriverBase);
  111.    if (mesadriverBase == NULL)
  112.    {
  113.      mesaautoopenfail("mesamain.library", 2);
  114.      return 1;
  115.    }
  116.  
  117.    return 0;
  118. }
  119.  
  120. CBMLIB_DESTRUCTOR(closemesa)
  121. {
  122.    if (mainlibbase)
  123.    {
  124.       CloseLibrary((struct Library *)mainlibbase);
  125.       mainlibbase = mesamainBase = NULL;
  126.       mesadriverBase = NULL;
  127.    }
  128. }
  129.